//
//  ZPShowEvaluateImageVC.m
//  ZhenPin
//
//  Created by fei on 14-8-26.
//  Copyright (c) 2014年 zhenpin. All rights reserved.
//

#import "ZPShowEvaluateImageVC.h"
#import "UIImageView+WebCache.h"
@interface ZPShowEvaluateImageVC ()

@end

@implementation ZPShowEvaluateImageVC

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

-(void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    [self.navigationController setNavigationBarHidden:YES animated:YES];
}
-(void)viewWillDisappear:(BOOL)animated {
}

- (void)viewDidLoad
{
    [super viewDidLoad];
	self.view.backgroundColor = [UIColor blackColor];
    self.automaticallyAdjustsScrollViewInsets = NO;
    
    imageScrollView = [[UIScrollView alloc] initWithFrame:self.view.frame];
    imageScrollView.backgroundColor = [UIColor clearColor];
    imageScrollView.scrollEnabled = YES;
    imageScrollView.pagingEnabled = YES;
    imageScrollView.delegate = self;
    imageScrollView.center = CGPointMake(self.view.frame.size.width/2, self.view.frame.size.height/2);
    imageScrollView.contentSize = CGSizeMake(320*self.imageArray.count, 480);
    imageScrollView.showsHorizontalScrollIndicator = NO;
    imageScrollView.showsVerticalScrollIndicator = NO;
    imageScrollView.clipsToBounds = YES;
    for (int i = 0; i < self.imageArray.count; i ++){
        
        
        UIImageView *imageview = [[UIImageView alloc] initWithFrame:CGRectMake(imageScrollView.frame.size.width*i, 0, imageScrollView.frame.size.width, imageScrollView.frame.size.height)];
        
        [imageview sd_setImageWithURL:[self.imageArray objectAtIndex:i] placeholderImage:[UIImage imageNamed:@"detail_noimage_b"]];
        imageview.contentMode = UIViewContentModeScaleAspectFit;
        imageview.userInteractionEnabled = YES;
        imageview.clipsToBounds = YES;
        imageview.tag = i+1;
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapGestureImage:)];
        [imageview addGestureRecognizer:tap];
        
        [imageScrollView addSubview:imageview];
        
        
    }
    
    [self.view addSubview:imageScrollView];
    
    showBigPageControl = [[UIPageControl alloc] initWithFrame:CGRectMake(0, self.view.frame.size.height-20-30, self.view.frame.size.width, 30)];
    showBigPageControl.numberOfPages = self.imageArray.count;
    showBigPageControl.tintColor = [UIColor grayColor];
    showBigPageControl.pageIndicatorTintColor = [UIColor lightGrayColor];
    showBigPageControl.currentPageIndicatorTintColor = [UIColor darkGrayColor];
    showBigPageControl.userInteractionEnabled = NO;
    [self.view addSubview:showBigPageControl];
    
    if (_selectIndex != 0) {
        [imageScrollView setContentOffset:CGPointMake(imageScrollView.frame.size.width*_selectIndex, 0) animated:NO];
        showBigPageControl.currentPage = _selectIndex;
    }
    
}
-(void)tapGestureImage:(UITapGestureRecognizer *)tapG {
    [self.navigationController popViewControllerAnimated:YES];
}

-(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{
    
    if (scrollView == imageScrollView){
        CGFloat x = scrollView.contentOffset.x;
        showBigPageControl.currentPage = x/self.view.frame.size.width;
        if (x==offSet){
            
        }
        else {
            offSet = x;
            for (UIScrollView *s in scrollView.subviews){
                if ([s isKindOfClass:[UIScrollView class]]){
                    [s setZoomScale:1.0];
                }
            }
        }
    }
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
